from typing import Union
from fastapi import FastAPI
import uvicorn
from starlette.responses import RedirectResponse

app = FastAPI()
@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/items/{item_id}")
# Union[str, None] 表示参数 q 可以是 str 类型或者 None 类型。
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}


def document():
    return RedirectResponse(url="/docs")

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)